<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%"
      :row-class-name="tableRowClassName">
      <el-table-column
        prop="id"
        label="编号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="电话"
        width="180">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱"
        width="180">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间"
        width="180">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址">
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page=currentPage
      :page-sizes="[5, 10, 15, 20]"
      :page-size=pageSize
      layout="total, sizes, prev, pager, next, jumper"
      :total=totals
      align="right">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'User_02',
  data () {
    return {
      tableData:[],
      currentPage:1,
      pageSize:5,
      totals:0
    }
  },
  methods:{
    getUsers() {
      let param = {"currentPage":this.currentPage,"pageSize":this.pageSize}
      this.$http.post("/user/list",param)
      .then(result=>{
        this.tableData = result.data.rows;
        this.totals = result.data.totals;
      })
      .catch(result=>{
        alert("请求失败！")
      })
    },
    tableRowClassName({row, rowIndex}) {
      if (rowIndex === 1) {
        return 'warning-row';
      } else if (rowIndex === 2) {
        return 'success-row';
      }
      return '';
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1
      this.getUsers();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getUsers();
    }
  },
  mounted() {
    this.getUsers()
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .el-table .warning-row {
    background: oldlace;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }
</style>
